﻿var orderByFlag = "orderBy"; //排序标识
var defautOrderField = "DATE_MODIFIED"; //默认排序字段
var pageSizeFlag = "pageSize"; //页面标识
var containsKeyWordSuffix = "_IsContainsKeyWord";
var containFieldsSuffix = "_ContainFields"; //包含多个字段的隐藏域的Id后缀名
var isSelectFieldSuffix = "_SelectField"; //是否最后一个字段的控件标识Id
var formAction = $("form").attr("action"); //页面提交地址
var cookieKeyFlag = formAction != undefined ? formAction.substr(1).replace("/", "_") + "_" : ""; //每个页面的cookie标识前缀
var searchFlag = "searchFrom"; //搜索来源

$(document).ready(function () {
    //搜索条件
    var conditionText = $.cookie(cookieKeyFlag + "ConditionText");
    if (conditionText === null) {
        conditionText = getSearchText();
        if (conditionText.length > 0) {
            conditionText = conditionText.length > 50 ? conditionText.substr(0, 50) + "..." : conditionText
            $("#HrQueryCondition").html("您搜索的是：" + conditionText);
            var custom = $.cookie(cookieKeyFlag + searchFlag);

            if (custom !== null && custom !== "") {
                addSearchLog(window.location.href, conditionText);
            }
        }
    } else {
        $("#HrQueryCondition").html(conditionText);
        removeCookie(cookieKeyFlag + "ConditionText");
    }

    //当搜索条件为空时进行条件判断，交互显示为叉，提示文本
    var searchSubmitTips = $("#searchSubmitTips");
    var searchSubmit = $("#searchSubmit");
    searchSubmit.find("button").removeAttr("disabled");
    searchSubmit.hover(function () {
        //获取搜索条件字典
        var dictCondition = searchCondition(true);
        if (dictCondition.length === 0) {
            searchSubmit.find("button").addClass("input-submit-disable");
            var buttonOffset = searchSubmit.offset();
            var left = buttonOffset.left - (searchSubmitTips.outerWidth() - searchSubmit.outerWidth()) / 2;
            var top = buttonOffset.top - (searchSubmit.outerHeight() + 10);
            searchSubmitTips.fadeIn(100).css({ "left": left, "top": top });
        }
    }, function () {
        var button = searchSubmit.find("button");
        var disable = button.hasClass("input-submit-disable");
        if (disable) {
            button.removeClass("input-submit-disable");
        }
        searchSubmitTips.fadeOut(50);
    });

    //回车事件处理
    $(document).keyup(function (ev) {
        if (ev.keyCode === 13) {
            ev = ev || window.event;
            var target = ev.target || ev.srcElement;
            var obj = $(target).parent();
            //结果页中翻页
            if (obj.hasClass("bottom-page")) {
                InputPageIndex(obj);
            }
            else {
                //获取搜索条件字典
                var dictCondition = searchCondition(true);
                if (dictCondition.length === 0) {
                    var buttonOffset = searchSubmit.offset();
                    var left = buttonOffset.left - (searchSubmitTips.outerWidth() - searchSubmit.outerWidth()) / 2;
                    var top = buttonOffset.top - (searchSubmit.outerHeight() + 10);
                    searchSubmitTips.fadeIn(100).css({ "left": left, "top": top });
                    searchSubmitTips.delay(5000).fadeOut(50);
                }
                else {
                    return buttonSubmit();
                }
            }
        }
    });

    searchSubmit.bind("click", function () {
        return buttonSubmit();
    });

    getCompanyInfo();

    //简历曝光统计
    var resumeids = "";
    $(".resumes-list tr.info").each(function () {
        resumeids += $(this).attr("tag").toString().split("_")[0] + ",";
    });
    if (resumeids.length > 0) {
        dyweTrackEventExpo('resume', 'expo', resumeids);
    }

});

//获取公司信息
function getCompanyInfo() {
    $.getJSON("/Json/CompanyInfo", function (data) {
        if (data != null) {
            $("#DownloadBalanceCount").text(data.DownloadBalanceCount);
            $("#DownloadResumeCount").text(data.DownloadResumeCount);
            $("#TemporaryResumeCount").text(data.TemporaryResumeCount);
        }
    });
}

//获取搜索条件字段
function getQueryCondition() {
    //过滤数字文本框中输入非数字的文本框
    checkInputnumber();
    var inputs = $('*[name^=SF_1_]'); //form:first *[name^=SF_1_]
    var dictCondition = new Array();
    inputs.each(function () {
        var input = $(this);
        var key = input.attr("name");
        var value = (input.val() == input.attr("placeholder")) ? '' : input.val();
        if (input.attr("type") === "radio") {
            value = $('input:radio[name=' + key + ']:checked').val();
            dictCondition[key] = undefined;
        }
        else if (input.attr("type") === "checkbox") {
            if ($(input).attr("checked")) { value = "1"; }
            else { value = ""; }
        }
        var oldValue = dictCondition[key];
        if (oldValue != undefined) {
            if (value != "" && oldValue != "") {
                value = oldValue + "," + value;
                value = value.replace(/[ ]/g, "");
            }
            else if (key == "SF_1_1_8" && value == "" && oldValue != "") {
                value = oldValue + ",99";
            }
            else { value = ""; }
        }
        dictCondition[key] = $.trim(value);
    });
    return dictCondition;
}

//返回选定搜索项时，去除cookie中搜索器中的搜索项
$("#filterConnditions").click(function () {
    $(this).remove();
    removeCookie("SearchByCunstom_searcherConditions");
    return buttonSubmit();
});
//整理搜索字典的搜索条件并判断是否排除照片和简历语言筛选条件
//isFilter为true即为排除照片和简历语言筛选条件
function searchCondition(isFilter) {
    var dictCondition = getQueryCondition();
    var aParam = new Array();
    for (var key in dictCondition) {
        if (key.indexOf(containsKeyWordSuffix) > -1 || key.indexOf(containFieldsSuffix) > -1 || key.indexOf(isSelectFieldSuffix) > -1) continue;
        if (isFilter && (key == "SF_1_1_26")) continue;

        var value = encodeURIComponent(dictCondition[key]);
        if (value != null && value != "") {
            var containFieldsId = key + containFieldsSuffix;
            var condition = dictCondition[containFieldsId];
            if (condition != null) {
                var fields = condition.split(",");
                var field = fields[0];
                var isSel = $("#" + key + isSelectFieldSuffix).is(':checked');
                if (fields.length === 2) { if (isSel) { field = fields[1]; } }

                aParam.push(key + "=" + field + ":" + value);
            }
            else {
                var keyWordId = key + containsKeyWordSuffix;
                var keyCondition = dictCondition[keyWordId];
                if (keyCondition != null) {
                    var isSel = $("#" + keyWordId).is(':checked');
                    aParam.push(key + (isSel ? "=or-" : "=") + value);
                }
                else {
                    aParam.push(key + "=" + value);
                }
            }
        }
    }
    return aParam;
}

//清空查询条件
$("#clearConditionSettings").click(function () {
    getJump($("form:first").attr("action"));
    return false;
});

//获取搜索条件组成的查询参数
function getSubmitQuery() {
    var aParam = searchCondition(true);
    if (aParam.length > 0) {
        var orderByField = $.cookie(cookieKeyFlag + orderByFlag);
        if (orderByField === null) {
            orderByField = $("#" + orderByFlag).val();
        }
        if (orderByField != undefined && orderByField.length > 0) {
            //add by fish
            if (orderByField.toLowerCase().indexOf("birth_year") || orderByField.toLowerCase().indexOf("education_level")) {
                orderByField = defautOrderField + ",1";
            }
            setForeverCookie(cookieKeyFlag + orderByFlag, orderByField);
            aParam.push(orderByFlag + "=" + orderByField);
        }
        var pageSize = $.cookie(cookieKeyFlag + pageSizeFlag);
        if (pageSize !== null && pageSize.length > 0) {
            aParam.push(pageSizeFlag + "=" + pageSize);
        }
        if (formAction.toLowerCase().indexOf("custom") > -1) {
            setTempCookie(cookieKeyFlag + searchFlag, "custom");
        }
        else if (formAction.toLowerCase().indexOf("position") > -1) {
            aParam.push("departmentId=" + $("#rd-select-departments").find('option:selected').val());
        }
        if ($.query.get("zpssz") != null && $.query.get("zpssz") != '') {
            aParam.push("zpssz=1");
        }
        return "?" + aParam.join("&");
    }
    else {
        return "";
    }
}

//搜索条件补充
function queryAttach(rawQuery) {
    if (rawQuery.indexOf("SF_1_1_27") < 0)
        rawQuery += "&SF_1_1_27=0";
    else
        rawQuery = rawQuery.replace("SF_1_1_27=1", "SF_1_1_27=0");
    if (rawQuery.indexOf("exclude") < 0)
        rawQuery += "&exclude=1";
    return rawQuery;
}

//搜索条件提交
function buttonSubmit() {
    var submitQuery = getSubmitQuery();
    if (submitQuery.length > 0) {
        submitQuery = queryAttach(submitQuery);
        getJump(formAction + submitQuery);
    }
    return false;
}

/******************************
search.custom.js
******************************/

var searcherName = "S_N";
var searcherId = "S_ID";

//初始化公司名称控件
function InitCompanyName(companyValue) {
    if (companyValue === "") { return; }
    var key = "SF_1_1_25";
    var value = companyValue;
    var arrValue = value.split(":");
    var arrContainField = $("#" + key + containFieldsSuffix).val().split(",");
    var isSelectedField = false;
    if (arrValue.length > 1 && arrContainField !== null) {
        for (var i = 0; i < arrContainField.length; i++) {
            if (arrValue[0] === arrContainField[i]) {
                isSelectedField = i > 0 ? true : false;
                break;
            }
        }
    }
    var company = $("#" + key);
    $("#" + key + isSelectFieldSuffix).attr("checked", isSelectedField);
    company.css('color', (company.attr("placeholder") !== company.val() && company.val().length > 0) ? 'rgb(51, 51, 51)' : 'rgb(153, 153, 153)');
}

//获取查询条件描述
function getSearchText() {
    var inputs = $('form:first *[name^=SF_1_]');
    var arrValue = new Array();
    inputs.each(function () {
        var input = $(this);
        var name = input.attr("name");
        //排除照片和简历语言筛选条件
        if (name == "SF_1_1_26") { return; }
        var value = "";
        if (input.is(":text") && input.val() != input.attr("placeholder") && input.val() != "") {
            value = input.val();
        }
        else if (input.is(":hidden") && input.val() != "") {
            value = $("#button_" + name + "F").attr("title");
        }
        else if (input.is(":radio") && input.is(':checked')) {
            value = input.parent().text();
            //SF_1_1_9即为性别条件 性别条件不用--性别:女/男
            if (input.val() !== "" && name !== "SF_1_1_9") {
                value = $("#div_" + name).text() + ":" + value;
            }
        }
        else if (input.is("select")) {
            value = input.find("option:selected").text()
        }
        if (value != null && value.length > 0) {
            var oldValue = arrValue[name];
            if (oldValue != undefined && oldValue != value) {
                if (name == "SF_1_1_8" && (value == "99" || value == "100")) { arrValue[name] = oldValue + "岁-及以上"; }
                else if (name == "SF_1_1_8") { arrValue[name] = oldValue + "岁-" + value + "岁"; }
                else arrValue[name] = oldValue + "-" + value;
            }
            else { arrValue[name] = value; }
        }
        else {
            var oldValue = arrValue[name];
            if (name == "SF_1_1_8" && oldValue != undefined) { arrValue[name] = oldValue + "岁-及以上"; }
        }
    });
    var conditionText = "";
    for (var i in arrValue) {
        if (arrValue[i] != "不限") { conditionText = conditionText + "+" + arrValue[i]; }
    }
    return conditionText.substr(1);
}

//最近搜索条件
$("#devRecentlySerch").click(function () {
    var chtml = $("#devRdSerchLayer");
    if (!chtml.length) {
        var chtml = createTag("<div class='rd-search-layer fc315' id='devRdSerchLayer'>");
        var oUl = createTag("<ul></ul>", chtml);
    }
    $.getJSON("/Json/SearchLastList", function (data) {
        if (data != null && data.length > 0) {
            $(data).each(function () {
                createTag("<li><a href='" + this.Href + "'>" + decodeURIComponent(this.Text) + "</a></li>", oUl);
            });
        }
    });
    chtml.css({ "z-index": 9999 });
    $("body").append(chtml);
    $(document).click(function (e) {
        if ($(e.target).closest(chtml).length || $(e.target).closest("#devRecentlySerch").length) {
            return;
        }
        $.popupBase.close(chtml);
    });
    $.popupBase.init({
        div: chtml,
        maskable: false,
        posx: $(this).offset().left - $(document).scrollLeft(),
        posy: $(this).offset().top - $(document).scrollTop() + $(this).height() + 2
    });
    function createTag(str, parent) {
        var temp = $(str);
        if (parent) {
            temp.appendTo(parent);
        }
        return temp;
    }
});
function showSearchList() {
    var chtml = $("#searcherSwitcher_div");
    var maxSearchNum = 99;
    if (!chtml.length) {
        //创建元素
        var chtml = createTag("<div id='searcherSwitcher_div' class='popupSearcher'></div>");
        var title = createTag("<div class='title'></div>", chtml);
        var rightTitle = createTag("<div style='float:right;' class='clearSearcher'></div>", title);
        var contentWrap = createTag("<div class='content' style='padding: 0px;height:200px;'>", chtml);
        var content = createTag("<div style='padding-top: 5px; padding-right: 3px; padding-left: 3px;'>", contentWrap);
        var oUl1 = createTag("<ul id='searcherList'></ul>", content);
    }
    //加载搜索器列表
    $.getJSON("/Json/SearcherList", function (data) {
        oUl1 = chtml.find("#searcherList");
        oUl1.text('');
        var liNum = 0;
        if (data != null && data.length > 0) {
            $(data).each(function () {
                var li = createTag("<li tag='" + this.ConditionStr + "' id='" + this.ID + "'><a style='float:right;' class='clearIt'></a><a class='choose' style='cursor: hand; cursor: pointer;' title='" + this.DisplayName + "'>" + this.DisplayName + "</a></li>", oUl1);
            });
            $(".choose").bind("click", function () {
                $.popupBase.close($("#searcherSwitcher_div"));
                //$("#delSerchSpan").hide();
                var id = $(this).parent().attr("id");
                var displayName = $(this).text();
                var href = $(this).parent().attr("tag");
                var redirectUrl = href + "&" + searcherId + "=" + id + "&" + searcherName + "=" + encodeURIComponent(displayName);
                removeCookie("SearchByCunstom_searcherConditions");
                redirectUrl = queryAttach(redirectUrl);
                getJump((window.location.pathname == '/' || window.location.pathname == '/Home/SearchByCustom') ? ('/Home/ResultForCustom' + redirectUrl) : redirectUrl);
            });
            liNum = $('#searcherList li').length;
            $("#searchNum").html(maxSearchNum - liNum);
            $(".clearIt").bind("click", function () {
                var r = confirm("确定要删除此搜索器吗？");
                if (r == true) {
                    var searcherId = $(this).parent().attr('id');
                    $(this).parent().remove();
                    $('#searchNum').text(parseInt($('#searchNum').text()) + 1);
                    //数据库删除
                    $.getJSON("/Json/DeleteSearcherById", { id: searcherId });
                }
                else {
                    return false;
                }
            });
        }
        var leftTitle = createTag("<div style='float:left;'>还可保存<em id='searchNum'>" + (maxSearchNum - liNum) + "</em>个搜索器：</div>", title);
        //关闭搜索器
        $(".clearSearcher").bind("click", function () {
            $.popupBase.close(chtml);
        });
    });

    $("body").append(chtml);
    //点击其它地方关闭弹窗
    $(document).click(function (e) {
        if ($(e.target).closest(chtml).length || $(e.target).closest("#devSearcherSwitcher").length || $(e.target).closest(".clearIt").length) {
            return;
        }
        $.popupBase.close(chtml);
    });
    //定位弹层
    $.popupBase.init({
        div: chtml,
        maskable: false,
        posx: $("#devSearcherSwitcher").offset().left - $(document).scrollLeft() - 69,
        posy: $("#devSearcherSwitcher").offset().top - $(document).scrollTop() + $("#devSearcherSwitcher").height() + 2
    });
    //生成元素方法
    function createTag(str, parent) {
        var temp = $(str);
        if (parent) {
            temp.appendTo(parent);
        }
        return temp;
    }
    setTimeout(function () {
        $("#fixedPopupIframe").css("display", "inline");
    }, 0);
}
//弹出搜索器列表
$("#devSearcherSwitcher").click(function () {
    showSearchList();
});

//保存搜索条件
function SaveHrQueryConditionSettings(dataList, popupId) {
    $.getJSON("/Json/SaveQueryCondition", { conditionId: dataList }, function (data) {
        if (data) {
            $.popupBase.close(popupId);
            if (window.location.pathname != null && window.location.pathname == "/Home/ResultForCustom") {
                buttonSubmit();
            }
            else window.location.reload();
            //buttonSubmit();
        }
    });
}

//设置搜索条件
$("#HrQueryConditionSettings").click(function () {
    $.getJSON("/Json/QueryConditionList", function (data) {
        $(this).selection({
            title: "设置搜索条件",
            noSelectTitle: "添加搜索条件",
            noSelectTips: data.length + "个搜索条件供选择",
            selectTitle: "已选择搜索条件",
            selectTips: "最少选6个，最多选9个",
            defaultContent: "（职位名称、所在行业、更新日期、工作年限、学历、现居住地、期望工作地）",
            data: data,
            max: 9,
            min: 6,
            buttonMethod: function (dataList, popupId) {
                var conditions = searchCondition(false);
                setTempCookie(cookieKeyFlag + "ConditionSettings", conditions);
                var hrQueryConditionDes = $("#HrQueryCondition");
                if (hrQueryConditionDes != undefined) {
                    setTempCookie(cookieKeyFlag + "ConditionText", hrQueryConditionDes.text());
                }
                removeCookie("SearchByCunstom_searcherConditions");
                SaveHrQueryConditionSettings(dataList, popupId);
            }
        });
    });
});

/******************************
search.position.js
******************************/

var job_Id = "SF_1_2_1";
var desired_job_type_Id = "SF_1_2_17";
var desired_employment_type_Id = "SF_1_2_19";
var desired_city_Id = "SF_1_2_18";
var work_year_Id = "SF_1_2_4";
var education_level_Id = "SF_1_2_5";
var advanced_management_Id = "SF_1_2_23";

//部门列表选择事件
$("#rd-select-departments").change(function () {
    var value = $(this).children('option:selected').val();
    if (value.length === 0) {
        $("#rd-select-positions").addClass("rd-resume-disabled");
    }
    else {
        $("#rd-select-positions").removeClass("rd-resume-disabled");
    }
    ClearPositionInfo();
});

//点击选择职位列表
$("#rd-select-positions").click(function () {
    if ($(this).hasClass("rd-resume-disabled"))
        return;
    //创建元素
    var chtml = $("#devRdtextarea");
    if (!chtml.length) {
        chtml = createTag("<div class='rd-textarea' id='devRdtextarea'><ul id='positionList'>&nbsp;&nbsp;数据加载中...</ul></div>");
    }
    var oUl = chtml.find("#positionList");
    if (oUl.find("li").length === 0) {
        var deptId = $("#rd-select-departments").find('option:selected').val();
        //加载职位列表
        $.getJSON("/Json/Positions", { departmentId: deptId }, function (data) {
            if (data === null) {
                oUl.html("&nbsp;&nbsp;职位列表加载失败");
            }
            else if (data.length === 0) {
                oUl.html("&nbsp;&nbsp;暂无职位");
            }
            else {
                oUl.html("");
                $(data).each(function () {
                    var context = this;
                    var li = createTag("<li><a class='fc333' href='javascript:void(0)'>" + context.JobDisplayTitle + "</a></li>", oUl);
                    li.bind("click", function () {                        
                        SetPositionInfo(context);
                    });
                });
            }
        });
    }
    chtml.css({ "z-index": 9999 });
    $("body").append(chtml);
    $(document).click(function (e) {
        if ($(e.target).closest(chtml).length || $(e.target).closest("#devRdtextarea").length) {
            return;
        }
        $.popupBase.close(chtml);
    });
    $.popupBase.init({
        div: chtml,
        maskable: false,
        posx: $(this).offset().left - $(document).scrollLeft(),
        posy: $(this).offset().top - $(document).scrollTop() + $(this).height()
    });
    function createTag(str, parent) {
        var temp = $(str);
        if (parent) {
            temp.appendTo(parent);
        }
        return temp;
    }
    return false;
});

//清空选择的职位信息
function ClearPositionInfo() {
    var chtml = $("#devRdtextarea");
    chtml.html("<ul id='positionList'>&nbsp;&nbsp;数据加载中...</ul>");
    $("#rd-select-positions .rd-popinput").val("选择职位").attr("title", "选择职位");

    if ($("#rd-search_query").is(":visible")) {
        $("#" + job_Id).val("");
        $("#rd-search-JobTitle").text("");

        $("#" + desired_job_type_Id).val("");
        $("#rd-search-JobTypeNames").text("");

        $("#" + desired_employment_type_Id).val("");
        $("#rd-search-EmploymentType").text("");

        $("#" + desired_city_Id).val("");
        $("#button_" + desired_city_Id + "F").val("").attr("title", "");
        lib_select(work_year_Id, arrWorkYear, "");
        lib_select(education_level_Id, arrEducation, "");
        lib_radio(advanced_management_Id, arrManagemenExperience, "");
        $("#rd-search_query").css('display', 'none');
    }
}

//获取选择职位的信息
function SetPositionInfo(context) {
    $("#devRdtextarea").hide();
    var ifCutPositionName = location.href.toLowerCase().indexOf("resultforposition");
    if (ifCutPositionName > -1) {
        $("#rd-select-positions .rd-popinput").val(cutstr(context.JobDisplayTitle, 26)).attr("title", context.JobDisplayTitle);
    }
    else { $("#rd-select-positions .rd-popinput").val(context.JobDisplayTitle).attr("title", context.JobDisplayTitle); }
    $("#" + job_Id).val(context.JobTitle);
    $("#rd-search-JobTitle").text(context.JobDisplayTitle);

    $("#" + desired_job_type_Id).val(context.JobTypeIds.replace(',',';'));
    $("#rd-search-JobTypeNames").text(context.JobTypeNames);

    $("#" + desired_employment_type_Id).val(context.EmploymentTypeId);
    $("#rd-search-EmploymentType").text(context.EmploymentTypeName);

    $("#" + desired_city_Id).val(context.CityID);
    setCity(context.CityID, $("#button_" + desired_city_Id + "F"));

    lib_select(work_year_Id, arrWorkYear, context.ExperienceRequired);
    lib_select(education_level_Id, arrEducation, context.EducationRequired);
    lib_radio(advanced_management_Id, arrManagemenExperience, context.ManagementExperienceRequired);
    var value = context.JobDisplayTitle + "|" + context.JobTypeNames + "|" + context.EmploymentTypeName
    setTempCookie(cookieKeyFlag + "positionInfo", value);

    $("#rd-search_query").css('display', 'block');
}

/******************************
search.list.js
******************************/
var pageIndexFlag = "pageIndex"; //页码标识
var displayModeFlag = "displayMode"; //展示方式标识

$(document).ready(function () {
    //获取页面大小
    var pageSize = $.query.get(pageSizeFlag);
    $(".resumelist-num-icon").each(function () {
        if (pageSize === "") { pageSize = "30"; }
        var text = $.trim($(this).text());
        if (pageSize === text) { $(this).addClass("number-current current-icon-default"); }
    });
    //var radioList = $('input:radio[name=orderBy]');
    //radioList.attr('checked', false);
    //获取排序指定字段
    var orderBy = $.query.get(orderByFlag);
    var filedId = orderBy.split(",");
    if (filedId.length > 1) {
        //新增的四组排序方式初始化  jjj 20130123
        var orderBySpan = $("#orderBy_" + filedId[0]);
        if (filedId[0] === "EDUCATION_LEVEL") {
            if (filedId[1] === "0") {
                orderBySpan.find("span").removeClass("showimg-up").addClass("showimg-up-current");
            } else {
                orderBySpan.find("span").removeClass("showimg-up").addClass("showimg-down-current");
                orderBySpan.attr("title", "学历由高到低排序");
            }
        }
        else if (filedId[0] !== defautOrderField) {
            if (filedId[1] === "0") {
                orderBySpan.find("span").removeClass("showimg-up").addClass("showimg-down-current");
            } else {
                orderBySpan.find("span").removeClass("showimg-up").removeClass("showimg-down").addClass("showimg-up-current");
                orderBySpan.attr("title", "年龄由低到高排序");
            }
        } else {
            orderBySpan.find("span").removeClass("bule-icon-01").addClass("bule-icon-current-01");
        }
        orderBySpan.addClass("blue-border-current");
    }
    else {
        //if (radioList.length == 2) { radioList[1].checked = true; }
        //新增的相关度排序初始化  jjj 20130123
        $("#orderBy_score").find("span").removeClass("bule-icon-02").addClass("bule-icon-current-02");
        $("#orderBy_score").addClass("blue-border-current");
        $("#excludeTips").attr("title", "同一求职者的多份简历只显示最相关的一份");
    }
    //获取列表展示方式 默认为列表模式
    var model = $.cookie(cookieKeyFlag + displayModeFlag);
    model = (model !== null && model === "detail") ? "detail" : "list";
    displayMode(model, true);
});

//输入页码转向新页
function InputPageIndex(context) {
    var currentPage = 1;
    var pageCount = 1;
    var arrPage = $("#rd-resumelist-pageNum").text().split("/");
    if (arrPage.length == 2) {
        currentPage = parseInt(arrPage[0]);
        pageCount = parseInt(arrPage[1]);
    }
    var input = context.parent().find(".rd-resumelist-page");
    var inputNum = input.val();
    var pageIndex = parseInt(inputNum);
    if (pageIndex == currentPage) {
        return;
    }
    if (pageIndex >= 1 && pageIndex <= pageCount) {
        jumpNewPage($.query.set(pageIndexFlag, pageIndex));
    }
    else if (pageIndex < 1) {
        jumpNewPage($.query.set(pageIndexFlag, pageCount > 1 ? 1 : 1));
    }
    else if (pageIndex > pageCount) {
        jumpNewPage($.query.set(pageIndexFlag, pageCount));
    }
    else {
        input.val(1);
    }
}

//展示简历详情
function showResumeInfo(trInfo) {
    var img = trInfo.find("img");
    var tagPath = img.attr("tag");
    if (tagPath !== "") { img.attr("src", img.attr("tag")); }
    trInfo.show();
}

//判断列表显示的展示方式
function displayMode(model, isFrom) {
    var arrTr = $(".resumes-list>form>table>tbody>tr.info");
    if (model == "detail") {
        for (var i = 0; i < arrTr.length; i++) {
            if ($(arrTr[i]).attr("tag") != undefined) {
                var cookieKey = cookieKeyFlag + displayModeFlag + "_" + $(arrTr[i]).attr("tag");
                if (isFrom) {
                    var isShow = $.cookie(cookieKey);
                    if (isShow != null && isShow == "0") { $(arrTr[i]).hide(); }
                    else { showResumeInfo($(arrTr[i])); }
                }
                else {
                    removeCookie(cookieKey);
                    showResumeInfo($(arrTr[i]));
                }
            }
            if (i == arrTr.length - 1) {
                $(arrTr[i]).prev().removeClass("last-bottom");
                $(arrTr[i]).prev().attr("tag", "last");
            }
        }
        if ($("#displayModel-list") != undefined) {
            $("#displayModel-list").removeClass("manner-icon1-current").addClass("manner-icon1");
            $("#displayModel-detail").removeClass("manner-icon2").addClass("manner-icon2-current");
        }
    }
    else {
        for (var i = 0; i < arrTr.length; i++) {
            if ($(arrTr[i]).attr("tag") != undefined) {
                var cookieKey = cookieKeyFlag + displayModeFlag + "_" + $(arrTr[i]).attr("tag");
                if (isFrom) {
                    var isShow = $.cookie(cookieKey);
                    if (isShow != null && isShow == "1") { showResumeInfo($(arrTr[i])); }
                    else { $(arrTr[i]).hide(); }
                }
                else {
                    removeCookie(cookieKey);
                    $(arrTr[i]).hide();
                }
            }
            if (i == arrTr.length - 1) {
                $(arrTr[i]).prev().addClass("last-bottom");
                $(arrTr[i]).prev().attr("tag", "last");
            }
        }
        if ($("#displayModel-list") != undefined) {
            $("#displayModel-list").removeClass("manner-icon1").addClass("manner-icon1-current");
            $("#displayModel-detail").removeClass("manner-icon2-current").addClass("manner-icon2");
        }
    }
}

//展示模式
$(".rd-resumelist-manner").click(function () {
    var model = $(this).attr("tag");
    setForeverCookie(cookieKeyFlag + displayModeFlag, model);
    displayMode(model, false);
});

//每页显示个数
$(".resumelist-num-icon").click(function () {
    if ($(this).hasClass("current")) return;
    var pageSize = $.trim($(this).text());
    if (pageSize === "60") {
        setForeverCookie(cookieKeyFlag + pageSizeFlag, pageSize);
        jumpNewPage($.query.remove(pageIndexFlag).set(pageSizeFlag, pageSize));
    }
    else {
        removeCookie(cookieKeyFlag + pageSizeFlag, pageSize);
        jumpNewPage($.query.remove(pageIndexFlag).remove(pageSizeFlag));
    }
});

//分页
$(".rd-resumelist-img").click(function () {
    if (!$(this).hasClass("gray-icon-go")) {
        InputPageIndex($(this));
    }
});

//排序
$(".showimg-click").click(function () {
    var filedId = $(this).attr("tag");
    var query = null;
    if (filedId === defautOrderField) {
        if ($("#orderBy_score").attr("checked") == "checked") {
            query = $.query.set(orderByFlag, filedId + ($(this).children().hasClass("showimg-up") ? ",1" : ",0"));
        }
        else {
            query = $.query.set(orderByFlag, filedId + ($(this).children().hasClass("showimg-up") ? ",0" : ",1"));
        }
    }
    else {
        query = $.query.set(orderByFlag, filedId + ($(this).children().hasClass("showimg-up") ? ",1" : ",0"));
    }
    if (query != null) { jumpNewPage(query); }
    return false;
});

$(".blue-border").click(function () {
    var filedId = $(this).attr("tag");
    var query = null;
    var orderByField;
    if (filedId === defautOrderField) {
        orderByField = defautOrderField + ",1";
        setForeverCookie(cookieKeyFlag + orderByFlag, orderByField);
        query = $.query.set(orderByFlag, orderByField);
    }
    else if (filedId === "score") {
        setForeverCookie(cookieKeyFlag + orderByFlag, "");
        query = $.query.remove(orderByFlag);
    }
    else {
        var orderFlag;
        orderFlag = $(this).find(".showimg-up,.showimg-down-current");
        if (orderFlag.length > 0) {
            if (filedId === "EDUCATION_LEVEL") {
                orderByField = $(this).attr("tag") + ",0";
            } else {
                orderByField = $(this).attr("tag") + ",1";
            }
            setForeverCookie(cookieKeyFlag + orderByFlag, orderByField);
            query = $.query.set(orderByFlag, orderByField);
        } else {
            if (filedId === "EDUCATION_LEVEL") {
                orderByField = $(this).attr("tag") + ",1";
            } else {
                orderByField = $(this).attr("tag") + ",0";
            }
            setForeverCookie(cookieKeyFlag + orderByFlag, orderByField);
            query = $.query.set(orderByFlag, orderByField);
        }
    }
    if (query != null) { jumpNewPage(query); }
    return false;
});

//每行显示列表与详情
$(".rd-show-btn a").click(function () {
    var closedTr = $(this).closest("tr");
    var trInfo = closedTr.next();
    var isLast = closedTr.attr("tag") === "last";
    var isDisplayList = $("#displayModel-list").hasClass("manner-icon1-current");
    var resmeId = trInfo.attr("tag");
    var cookieKey = cookieKeyFlag + displayModeFlag + "_" + resmeId;
    if (trInfo.is(':visible')) {
        if (!isDisplayList) { if (resmeId != undefined) { setTempCookie(cookieKey, "0"); } }
        else { removeCookie(cookieKey); }
        trInfo.hide();
        if (isLast) { closedTr.addClass("last-bottom"); }
    }
    else {
        if (isDisplayList) { if (resmeId != undefined) { setTempCookie(cookieKey, "1"); } }
        else { removeCookie(cookieKey); }
        showResumeInfo(trInfo);
        if (isLast) { closedTr.removeClass("last-bottom"); }
    }
})

//初始化显示字段设置 注释 jjj 20130125
function InitHrInfoFieldSettings() {
    var hrId = $("#HrInfoFieldSettings").attr("tag");
    if ($.cookie(hrId) !== null && $.cookie(hrId) === "true") {
        $(".similar-tips").hide();
    }
    else {
        $(".similar-tips").delay(1000).fadeIn(500);
    }
    $(".similar-list-tips").click(function () {
        $(this).hide();
        setForeverCookie(hrId, true);
    });
}

//显示字段设置
function SaveHrInfoFieldSettings(dataList, popupId) {
    $.getJSON("/Json/SaveInfoField", { fieldId: dataList }, function (data) {
        if (data || data == 'true') {
            $.popupBase.close(popupId);
            window.location.reload();
        }
    });
}

//设置显示字段
$("#HrInfoFieldSettings").click(function () {
    //$(".similar-list-tips").hide();
    setForeverCookie($(this).attr("tag"), true);
    $.getJSON("/Json/InfoFieldList", function (data) {
        $(this).selection({
            title: "设置显示字段",
            noSelectTitle: "添加显示字段",
            noSelectTips: (data.length - 2) + "个属性供选择",
            selectTitle: "已选择显示字段",
            selectTips: "最少选7个，最多选8个",
            defaultContent: "（简历名称、职位名称、学历、性别、年龄、现居住地、更新时间）",
            data: data,
            max: 8,
            min: 7,
            buttonMethod: function (dataList, popupId) {
                SaveHrInfoFieldSettings(dataList, popupId);
            }
        });
    });
});
